/*用户列表*/
layui.use('table', function(){
    var table = layui.table;
    table.render({
        id:"articleForm",
        elem: '#articleForm',
        url:'getArticle.html',
        method: 'POST', //方式
        page:{
            //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 1, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false //不显示尾页
        },
        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        cols: [ [
            {type:'checkbox'},
            {field:'title', title: '标题', sort: true},
            {field:'categoryId',    title: '栏目', sort: true},
            {field:'content',   title: '内容', sort: true},
            {field:'status',   title: '状态', templet: '#statusTpl'},
            {field:'gmtCreate',   title: '创建时间', sort: true}
        ] ]
    });
});
function add() {
    window.location.href = "/blog/article/addPage.html";
}
function edit(){
    var table = layui.table;
    var rows = table.checkStatus('articleForm'); //test即为基础参数id对应的值
    var id = rows.data[0].userId;
    if(rows.data.length!=1){
        layer.msg('请选择一条数据');
        return false;
    }else {
        var url = 'sys/user/edit.html?userId='+id;
        parent.layer.open({
            type: 2,
            title: '用户管理-编辑',
            shadeClose: true,
            skin: 'layui-layer-molv',
            shade: 0.8,
            area: ['30%', '77%'],
            content: [url,'no'], //iframe的url
            end:function () {
                reloadTable("articleForm");
            }
        });
    }
}


function del(){
    var table = layui.table;
    var rows = table.checkStatus('articleForm'); //test即为基础参数id对应的值
    var ids=[];
    if(rows.data.length<1){
        layer.msg('请选择一条数据');
        return false;
    }
    for(var i=0;i<rows.data.length;i++){
        var rowid = rows.data[i].userId;
        ids.push(rowid);
    }

    //询问框
    layer.confirm('确认要删除用吗',{btn: ['确定','取消'],icon: 2,title:'删除用户',skin:'layui-layer-molv'},
        function(index){
            $.ajax({
                type: "POST",
                url:"delete.html",
                async: false,
                traditional:true,
                cache: false,
                dataType:"json",
                data:{'ids':ids},
                success:function (data) {
                    if(data.code == 0){
                        layer.close(index);
                        parent.layer.msg('删除成功');
                    }
                    if(data.code == 500){
                        layer.close(index);
                        parent.layer.msg("删除失败");
                    }
                    reloadTable("articleForm");
                }
            })
        }, function(){
        });
}

function search(){
    var userName = $("input[name='userName']").val();
    var mobile = $("input[name='mobile']").val();

    var table = layui.table;
    table.reload("articleForm", { //此处是上文提到的 初始化标识id
        where: {
            //key: { //该写法上文已经提到
            userName: userName,mobile:mobile
            //}
        }
    });
}

function configure() {
    var table = layui.table;
    var rows = table.checkStatus('articleForm');
    if(rows.data.length!=1){
        layer.msg('请选择一条数据');
        return false;
    }else{
        var id = rows.data[0].userId;
    }
    var url = 'sys/user/configure.html?userId='+id;
    parent.layer.open({
        title:'分配权限',
        type: 2,
        area: ['20%', '77%'],
        skin: 'layui-layer-rim', //加上边框
        content: [url,'no'], //iframe的url
        end:function () {
            reloadTable("articleForm");
        }
    });
}
